// 报修菜单的接口
import {
  request
} from '../request';


// 资产(设备、设备组、位置)
export function getEamMObileAssets(data) {
  return request({
    url: 'eis.simple?service=eamPageParamQueryService&method=getEamMobileAssetXmSelect',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 新增报修
export function addRepair(data, files) {
  let url = 'eis.simple?service=eamOrderService&method=createMROrder';
  let fileStr = '';
  if (files?.length > 0) {
    files.forEach((item) => {
      if (item.source && item.source === 'MOBILE') {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=MOBILE`;
      } else {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=DESKTOP`;
      }
    });
    url += fileStr;
  }

  return request({
    url: url,
    method: 'post',
    data: data
  });
}

// 根据资产选择人员
export function getPersonByAsset(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=getAssetDutyUser',
    method: 'post',
    isFormData: true,
    data: data,
    // headers: {
    //   'Content-Type': 'application/x-www-form-urlencoded'
    // }
  });
}

// 我的报修
export function getMyRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryMROrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 需审核的报修单
export function getAuditRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=planUserQueryMROrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 报修单详情
export function getMobileMROrderDetail(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=getMobileMROrderDetail',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 删除报修
export function deleteRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteMrOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 删除工单
export function deleteOrder(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteOrder',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 待评价报修单
export function getEvaluateRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryMROrder',
    isFormData: true,
    method: 'post',
    data: data
  });
}

// 编辑报修单
export function editRepair(data, files) {
  let url = 'eis.simple?service=eamOrderService&method=editMROrder';
  let fileStr = '';
  if (files?.length > 0) {
    files.forEach((item) => {
      if (item.source && item.source === 'MOBILE') {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=MOBILE`;
      } else {
        fileStr += `&filename=${item.filename || ''}&fileno=${item.fileno || ''}&source=DESKTOP`;
      }
    });
    url += fileStr;
  }

  return request({
    url: url,
    method: 'post',
    data: data
  });
}

//工单评价
export function evaluateRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=orderEstimate',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 取消报修
export function cancelRepair(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=cancelMR',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 查询 停机时间
export function queryOrderMachineStopTime(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=queryOrderMachineStopTime',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 新增 停机时间
export function createOrderMachineStop(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=createOrderMachineStop',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 编辑 停机时间
export function editWorkOrderMachineStop(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=editWorkOrderMachineStop',
    method: 'post',
    isFormData: true,
    data: data
  });
}

// 删除 停机时间
export function deleteOrderMachineStop(data) {
  return request({
    url: 'eis.simple?service=eamOrderService&method=deleteOrderMachineStop',
    method: 'post',
    isFormData: true,
    data: data
  });
}
